#include "comm.hpp"

int main()
{
  int shmid = GetShm();                              // 获取共享内存
  char *shamaddr = (char *)shmat(shmid, nullptr, 0); // 建立联系
  int fd = open(FIFO_FILE, O_WRONLY);
  if (fd < 0)
  {
    log(Fatal, "error string:%s,error code:%d", strerror(errno));
    exit(FIFO_OPEN_ERR);
  }

  // 开始通信
  while (true)
  {
    cout << "Please Enter:";
    fgets(shamaddr, 4096, stdin);

    write(fd, "c", 1); // 通知对方，实现同步通信方式
  }
  // 取消联系
  shmdt(shamaddr);
  close(fd);
  return 0;
}